package cn.kgc.springcloud.service.impl;

import cn.kgc.springcloud.clients.TagClient;
import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.vo.ClazzVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.springcloud.entity.Clazz;
import cn.kgc.springcloud.service.ClazzService;
import cn.kgc.springcloud.mapper.ClazzMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author mengshun
* @description 针对表【t_clazz】的数据库操作Service实现
* @createDate 2024-10-23 09:57:39
*/
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz>implements ClazzService{

    @Resource
    private TagClient tagClient;

    @Override
    public List<ClazzVO> clazzList() {
        List<Clazz> clazzes = baseMapper.selectList(null);

        // 遍历班级列表
        List<ClazzVO> collect = clazzes.stream().map(clazz -> {
            ClazzVO clazzVO = new ClazzVO();

            BeanUtils.copyProperties(clazz,clazzVO);
            Integer tagId = clazz.getTagid();

            // 根据班级的tagId  查询标签服务   openfeign
            Tag tag= tagClient.getTagById(tagId);

            clazzVO.setTag(tag);

            return clazzVO;
        }).collect(Collectors.toList());


        return collect ;
    }
}




